package com.longge;

public class FindPeakGrid {

    public int[] findPeakGrid(int[][] mat) {
        int[][] d = new int[][]{{1, 0}, {-1, 0}, {0, -1}, {0, 1}};

        for (int i = 0; i < mat.length; i++) {
            for (int j = 0; j < mat[0].length; j++) {
                boolean flag = true;
                for (int k = 0; k < 4; k++) {
                    int di = d[k][0] + i;
                    int dj = d[k][1] + j;
                    if (di >= 0 && dj >= 0 && di < mat.length && dj < mat[0].length) {
                        if (mat[di][dj] > mat[i][j]) {
                            flag = false;
                        }
                    }
                }
                if (flag) return new int[]{i, j};
            }
        }
        return new int[]{-1,-1};
    }

}
